/**
 * 
 */
package py.edu.ucom.cadira.game.event.war;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.game.war.WarUser;

/**
 * @author largonet
 * 
 */
public class EndTimeEvent extends WarGameEvent {
    private WarUser newPlayer;

    public EndTimeEvent() {
		this.newPlayer= new WarUser();
	}
	public EndTimeEvent(WarUser user) {
        this.newPlayer = user;
    }
    public WarUser getUser() {
        return newPlayer;
    }
	@Override
	public void fromXML(Document xml) {
		Element rootElement = xml.getRootElement();
		Element endTimeNode = rootElement.getChild("EndTimeEvent");
		Element usuarioNode = endTimeNode.getChild("usuario");
		newPlayer.fromXml(usuarioNode);
	}
	@Override
	public void toXML(Element root) {
		Element endTimeNode = new Element("EndTimeEvent");
		Element newPlayerNode = newPlayer.toXml();
		endTimeNode.addContent(newPlayerNode);
		
		root.addContent(endTimeNode);
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof EndTimeEvent)) {
			return false;
		}
		EndTimeEvent otherObj = (EndTimeEvent) obj;
		if (otherObj.getUser().equals(getUser())) {
			return true;
		}
		return false;
	}
}
